<script type="text/javascript">
	$(function(){
		$('input[name=question_add]').click(function(){
			$('.form tr:last').before('<tr><th>คำถาม </th><td><input type="text" name="title[]" /></td></tr>');
		})
		
		$('input[name=question_delete]').click(function(){
			if(confirm('ยืนยันการลบ'))
			{
				var me = $(this);
				$.post('questions/admin/questions/delete_question/' + $(this).attr('rel'),function(data){
					me.parent().parent().remove();
				})
			}
		})
	})
</script>
<h1 style="margin:0 0 15px;">คำถามชิงรางวัล</h1>
<form method="post" action="questions/admin/questions/save/<?php echo $category->id?>" enctype="multipart/form-data">
	<table class="form">
		
		<tr>
			<th>ชุดคำถาม</th>
			<td>
				<input type="text" name="name" value="<?php echo $category->name ?>" /> <input type="button" name="question_add" value="เพิ่มคำถาม" />
			</td>
		</tr>
		<?php foreach($category->question as $question): ?>
		<tr>
			<th>คำถาม </th>
			<td>
				<input type="text" name="title[]" value="<?php echo $question->title ?>" />
				<input type="hidden" name="question_id[]" value="<?php echo $question->id ?>" />
				<input type="button" name="question_delete" value="ลบ" rel="<?php echo $question->id ?>" />
			</td>
		</tr>
		<?php endforeach; ?>
		<tr>
			<th>คำถาม </th>
			<td><input type="text" name="title[]" /></td>
		</tr>
		<tr>	
			<th></th>
			<td>
				<?php echo form_submit('',lang('btn_submit'),'class="button"')?>
				<?php echo form_button('',lang('btn_back'),'class="button" onclick="window.location = \'questions/admin/questions\'"')?>
			</td>
		</tr>
	</table>
</form>
